package com.zqc.util;

import com.zqc.javabean.User;
import mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class UserTest {
    SqlSession session;
    UserMapper mapper;

    @Before//在所有测试方法执行前执行
    public void before(){
        //1、创建SqlSessionFactory对象
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        //2、创建SqlSession对象 true 自动提交事务
        session = factory.openSession(true);
        //3、调用session的方法namespace的名字.id
        mapper = session.getMapper(UserMapper.class);
    }
    @After//在所有测试方法执行后执行
    public void after(){
        //5、关闭资源
        session.close();
    }
    @Test
    public void selectAllUser(){
        List<User> users = mapper.selectAllUser();
        //4、打印测试
        for(User u:users){
            System.out.println(u);
        }
    }
/*    @Test
    public void selectById(){
        System.out.println(mapper.selectById(20));
    }
    @Test
    public void deleteByArray(){
        int [] ids={3,5};
        mapper.deleteByArray(ids);
    }*/
@Test
public void selectById(){
    System.out.println(mapper.selectById(20));
}
    @Test
    public void deleteByArray(){
        int [] ids={3,5};
        mapper.deleteByArray(ids);
    }
}
